import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:myflutterproject/views/loadinglayout.dart';
class CustomSingleChildLayoutDemo extends StatefulWidget{
  @override
  State<StatefulWidget> createState() =>CustomSingleChildLayoutState();
}

class CustomSingleChildLayoutState extends State<CustomSingleChildLayoutDemo>{
  int _loadType=0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar:  AppBar(
        title: Text('CustomSingleChildLayout'),
        centerTitle: true,
      ),
      body: Container(
        child: Column(
          children: [
            _myChild(Colors.amber, double.infinity, 50),
            _myChild(Colors.red, double.infinity, 100),
            _myChild(Colors.green, 200, 50),
            _myChild(Colors.grey, 20, 100),
            RaisedButton(
              onPressed: () {
                setState(() {
                  _loadType = 0;
                });
              },
              child: Text('加载中'),
            ),
            RaisedButton(
              onPressed: () {
                setState(() {
                  _loadType = 1;
                });
              },
              child: Text('加载成功'),
            ),
            RaisedButton(
              onPressed: () {
                setState(() {
                  _loadType = 2;
                });
              },
              child: Text('加载失败'),
            ),

          ],
        ),
      ),
    );
  }

  _myChild(Color color,double width,double height){
    return Container(
      color: color,
      width: width,
      height: height,
      child: _getContent(),
    );

  }
  _getContent(){
    switch(_loadType){
      case 1:
        return Text('我是加载完的内容');
      case 2:
        return LoadingLayout(isLoading:false);
      default:
        return LoadingLayout(isLoading:true);
    }

  }

}